<%@include file="/WEB-INF/header.jsp"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<div id="page-wrapper">
	<!-- 模态框（Modal） -->
	<form
		action="${pageContext.request.contextPath }/class/addClass.action"
		class="form-horizontal" role="form">
		<div class="modal fade" id="myModal" tabindex="-1" role="dialog"
			aria-labelledby="myModalLabel" aria-hidden="true">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal"
							aria-hidden="true">&times;</button>
						<h4 class="modal-title" id="myModalLabel">添加班级信息</h4>
					</div>
					<div class="modal-body">
						<div class="form-group">
							<label for="firstname" class="col-sm-2 control-label">班级编号</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" name="class_id" id=""
									placeholder="请输入班级编号" required="required">
							</div>
						</div>
						<div class="form-group">
							<label for="lastname" class="col-sm-2 control-label">素质教师编号</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" name="quality_id" id=""
									placeholder="请输入素质教师编号" required="required">
							</div>
						</div>
						<div class="form-group">
							<label for="firstname" class="col-sm-2 control-label">素质教师姓名</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" name="quality_name"
									id="" placeholder="请输入素质教师姓名" required="required">
							</div>
						</div>

					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
						<button type="submit" class="btn btn-primary">提交</button>
					</div>
				</div>
				<!-- /.modal-content -->
			</div>
			<!-- /.modal -->
		</div>
	</form>
	<table class="table table-striped">
		<caption>
			<!-- 按钮触发模态框 -->
			<c:if test="${sessionScope.USER_SESSION.user_name ==  l.quality_id || sessionScope.USER_SESSION.user_rank == 1}">
			<div class="col-md-3 data1">
				<button class="btn btn-primary btn-sm" data-toggle="modal"
					data-target="#myModal">添加班级信息</button>
				<br />
			</div>
			</c:if>
			<br />
			<form
				action="${pageContext.request.contextPath}/class/findAll.action"
				method="post" class="form-horizontal" role="form">
				<div class="col-md-3 data1">
					<input type="text" class="form-control" name="data"
						placeholder="请输入查询内容" value="">
				</div>
				<button type="submit" class="btn bg-maroon">搜索</button>
			</form>
		</caption>
		<thead>
			<tr>
				<th>序号</th>
				<th>班級编号</th>
				<th>素质教师编号</th>
				<th>素质教师姓名</th>
				<th>操作</th>
			</tr>
		</thead>
		<tbody>
				<c:forEach items="${classlist}" var="l" varStatus="num">
				<c:if test="${sessionScope.USER_SESSION.user_name ==  l.quality_id || sessionScope.USER_SESSION.user_rank == 1}">
					<tr>
						<td>${num.index+1}</td>
						<td>${l.class_id}</td>
						<td>${l.quality_id}</td>
						<td>${l.quality_name}</td>
						<c:if test="${sessionScope.USER_SESSION.user_rank == 1 }">
							<td><a href="#" class="btn btn-info btn-xs"
								data-toggle="modal" data-target="#goodEditDialog" role="button"
								onclick="returnInfor(${l.id})">修改</a> <a
								href="${pageContext.request.contextPath }/class/delClass.action?classid=${l.id}"
								onclick="javascript:return confirm('确实要删除该班级吗?')"
								class="btn btn-danger btn-xs" role="button">删除</a></td>
						</c:if>
						<c:if test="${sessionScope.USER_SESSION.user_rank == 3 }">
						<td><a
							href="${pageContext.request.contextPath }/student/findAll.action?data=${l.class_id}"
							class="btn btn-outline-info" role="button">详情</a></td>
						</c:if>
					</tr>
					</c:if>
				</c:forEach>
			<div class="modal fade" id="goodEditDialog" tabindex="-1"
				role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
				<div class="modal-dialog">
					<div class="modal-content">
						<div class="modal-header">
							<button type="button" class="close" data-dismiss="modal"
								aria-hidden="true">&times;</button>
							<h4 class="modal-title" id="myModalLabel">修改班级</h4>
						</div>
						<div class="modal-body">
							<form id="edit_user_form">
								<div class="form-group">
									<label for="firstname" class="col-sm-2 control-label">序号</label>
									<div class="col-sm-10">
										<input type="text" class="form-control" name="id" id="id"
											readonly>
									</div>
								</div>
								<div class="form-group">
									<label for="firstname" class="col-sm-2 control-label">班级编号</label>
									<div class="col-sm-10">
										<input type="text" class="form-control" name="class_id"
											id="class_id" placeholder="请输入班级编号" required="required">
									</div>
								</div>
								<div class="form-group">
									<label for="firstname" class="col-sm-2 control-label">教师标号</label>
									<div class="col-sm-10">
										<input type="text" class="form-control" name="quality_id"
											id="quality_id" placeholder="请输入素质教师编号" required="required">
									</div>
								</div>
								<div class="form-group">
									<label for="firstname" class="col-sm-2 control-label">教师姓名</label>
									<div class="col-sm-10">
										<input type="text" class="form-control" name="quality_name"
											id="quality_name" placeholder="请输入素质教师姓名" required="required">
									</div>
								</div>
						</div>
						<div class="modal-footer">
							<button type="button" class="btn btn-default"
								data-dismiss="modal">关闭</button>
							<button type="submit" class="btn btn-primary"
								onclick="updateClass()">提交</button>
						</div>
					</div>
					<!-- /.modal-content -->
				</div>
				<!-- /.modal -->
			</div>
			</form>
		</tbody>
	</table>
	<div style="text-align: center">
		<button onclick="back()">返回</button>
	</div>
	<script type="text/javascript">
	// 通过id获取修改的商品信息
	  function returnInfor(id) {
			
			$.post("${pageContext.request.contextPath}/class/getclassId.action",{"id":id},function(data){
				$("#id").val(data.id);
				$("#class_id").val(data.class_id);
		         $("#quality_id").val(data.quality_id);
		         $("#quality_name").val(data.quality_name);
			});
		}
	  function updateClass() {
	  	
			$.post("${pageContext.request.contextPath}/class/updateClass.action",$("#edit_user_form").serialize(),function(data){
				if(data =="OK"){
					alert("班级信息修改成功！");
					window.location.reload();
				}else{
					alert("班级信息修改失败！");
					window.location.reload();
				}
			});
		}
</script>
</div>
<%@include file="/WEB-INF/footer.jsp"%>